package com.hd.appcommon.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.hd.appcommon.entity.Major;
import com.hd.appcommon.entity.Student;
import com.hd.appcommon.entity.User;
import com.hd.appcommon.entity.vo.StudentVo;
import com.hd.appcommon.mapper.UserMapper;
import com.hd.appcommon.service.MajorService;
import com.hd.appcommon.service.UserService;
import com.hd.hdxgddcommon.page.MyPage;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.function.Function;


@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    private StudentServiceImpl studentService;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private MajorService majorService;

    @Override
    public List<User> listByRoleId(String roleId) {
        return baseMapper.listByRoleId(roleId);
    }

    @Override
    public boolean updateBatchByQueryWrapper(Collection<User> entityList, Function<User, QueryWrapper<User>> queryWrapperFunction) {
        return false;
    }

    @Override
    public IPage<StudentVo> listStuMessage(MyPage page, QueryWrapper<User> queryWrapper) {
        IPage<StudentVo> studentVoIPage=userMapper.listStuMessage(page,queryWrapper);
        for (StudentVo studentVo:studentVoIPage.getRecords()){
            studentVo.setMajorName(majorService.getOne(new QueryWrapper<Major>().eq("code",studentVo.getMajorId())).getName());
        }
        return studentVoIPage;
    }

    @Override
    public void getSchoolRollChange() {

    }
}
